A little bit of everything

Suspend all active VM's during shutdown

I have some VM’s running on my Ubuntu Linux servers that do various tasks. I have some of them start on system startup, and I have some that I use on demand. Sometimes I forget to suspend a VM when shutting down or rebooting a server, or if a power outage occurs and the server goes to shut it self down, then the VM’s are terminated and not properly shutdown.

This script will properly suspend any running VM’s on the server.

Add it to your /etc/init.d directory
Be sure it is owned by root, and has execute privileges
Then install it with:
sudo update-rc.d vmwaresuspend defaults

Now every time your system shuts down, your VM’s will be properly suspended to disk!

------------

#!/bin/bash

#
# Suspend all running VM's for user when shutting down system
#
# dwentz 2010-10-31 New

### BEGIN INIT INFO
# Provides: vmwaresuspend
# Required-Start:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Required-Stop: 0 1 6
### END INIT INFO


# The Username to run as
export USER="dwentz" #<– my local user

export PATHTOVMS="/home/dwentz/Documents/VM"

export OPTIONS="-T player suspend"

. /lib/lsb/init-functions

case "$1" in

start)
#Nothing to be done for start.

exit 0

;;

stop)

vmrun -T player list|grep vmx$|while read VM

do

su ${USER} -c "/usr/bin/vmrun -T player suspend '$VM'"
log_action_begin_msg "Suspending vm ${VM} "

done

;;

restart)
# Nothing to be done for restart
exit 0
;;

esac

exit 0

------------

blog comments powered by Disqus